import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.Random;

/**
 * Represents a table for playing card games on. Can Contain a {@link Deck} or a {@link Game}.
 * 
 * @author Ricky Vincent
 */
public class Table {
	
	private Game game;
	private Dimension size;
	private Rectangle bounds;
	
	private Deck cards = new Deck();
	
	/**
	 * Constructs a new empty {@link Table} object.
	 */
	public Table() {
		setSize(new Dimension(1000,1000));
	}
	
	
	/**
	 * @return The {@link Deck} on this {@link Table}
	 */
	public Deck getDeck() {
		return getCards();
	}
	
	public Deck getCards() {
		return cards;
	}
	
	public void addDeck(Deck deck) {
		addNewCards(deck);
	}
	
	/**
	Adds new cards, for each one changing its ID if that ID is already taken.
	*/
	public void addNewCards(CardSet cs) {
		Random r = new Random();
		for (Card c: cs) {
			if (cards.getCardFromID(c.getID()) != null) {		// if the id is already taken
				c.autoAssignID();
			}
			c.setTable(this);
			c.setLocation(10 + r.nextInt(5), 10 + r.nextInt(5));	// random initial positions
			cards.add(c);
		}
	}
	
	public void addCards(CardSet cs) {
		cards.addAll(cs);
	}
	
	public void removeCards(CardSet cs) {
		cards.removeAll(cs);
	}
	
	public void removeAllCards() {
		cards.clear();
	}
	
	/**
	 * @return The {@link Game} on this {@link Table}
	 */
	public Game getGame() {
		return game;
	}

	/**
	 * @param game The {@link Game} to set.
	 */
	public void setGame(Game game) {
		this.game = game;
	}

	/**
	 * @param deck The {@link Deck} to set.
	 */
// 	public void setDeck(Deck deck) {
// 		this.deck = deck;
// 	}
	
	public void setSize(Dimension d){
		size = d;
		bounds = new Rectangle(size);
	}
	
	public boolean isInBounds(Rectangle c) {
		return bounds.contains(c);
	}
	
	public Dimension getSize(){
		return size;
	}
}
